package com.learn.rabbit.base.consumer;

import com.learn.rabbit.base.config.QueueConfig;
import com.learn.rabbit.base.config.RabbitmqConfig;
import com.learn.rabbit.base.dto.Info;
import com.learn.rabbit.base.dto.Message;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

/**
 * Consumer of queue which name is first-queue {@link QueueConfig#FIRST_QUEUE}
 *
 * @author zhousiqi
 * @version 1.0.0
 * @date 2019/2/26 18:19
 */
@Component
@Slf4j
@RabbitListener(queues = {QueueConfig.FIRST_QUEUE}, containerFactory = RabbitmqConfig.MULTI_LISTENER_CONTAINER)
public class FirstConsumer {

    /**
     * @param message 消息
     */
    @RabbitHandler
    public void handleMessage(String message) {
        // 处理消息
        log.info("FirstConsumer listen {}, handleMessage : {}", QueueConfig.FIRST_QUEUE, message);
    }

    /**
     * 参数可以用@Payload来接收实体
     *
     * @param info 消息
     */
    @RabbitHandler
    public void handleMessage(@Payload Info info) {
        // 处理消息
        log.info("FirstConsumer2 listen {}, handleMessage : {}", QueueConfig.FIRST_QUEUE, info);
    }

    /**
     * 参数可以用@Payload来接收实体
     *
     * @param message 消息
     */
    @RabbitHandler
    public void handleMessage(@Payload Message<Info> message) {
        // 处理消息
        log.info("FirstConsumer3 listen {}, handleMessage : {}", QueueConfig.FIRST_QUEUE, message);
    }
}
